﻿using Micro.Extensions.Utilities;
using Micro.Srv.LogCenter.Services.Interfaces;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace Micro.Srv.LogCenter.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LogController : ControllerBase
    {

        private readonly ILogService _logService;

        public LogController(ILogService logService)
        {
            _logService = logService;
        }


        /// <summary>
        /// 根据日志Id获取日志详细信息
        /// </summary>
        /// <param name="id">日志id</param>
        /// <returns></returns>
        [HttpGet("GetLogByObjectId")]
        public async Task<ComResult<MessageViewModel>> GetLogByObjectId(string id, DateTime beginTime, DateTime endTime)
        {
            return await _logService.GetLogByObjectIdAsync(id, beginTime, endTime);
        }

        /// <summary>
        /// 系统日志列表查询
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <returns></returns>
        [HttpPost("GetLogs")]
        public async Task<ComResult<MessageViewModel[]>> GetLogs([FromBody] LogSearchCondition condition)
        {
            return await _logService.GetLogsAsync(condition, condition.PageIndex, condition.PageSize);
        }
    }
}